package au.org.nh.servlet.context.listener;

import java.util.HashMap;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class ServletContextAppListener implements ServletContextListener {

	private static HashMap<String, String> lookedUpNames = new HashMap<String, String>();

	@Override
	public void contextInitialized(final ServletContextEvent arg0) {
		// Context ctx;
		// final Context envCtx;
		// try {
		// ctx = new InitialContext();
		// envCtx = (Context) ctx.lookup("java:comp/env");
		// final String dbName = (String) envCtx.lookup(ConfigParams.DB_NAME);
		// final String dbHost = (String) envCtx.lookup(ConfigParams.DB_HOST);
		// final String dbPort = (String) envCtx.lookup(ConfigParams.DB_PORT);
		// final String dbUsername = (String) envCtx
		// .lookup(ConfigParams.DB_USERNAME);
		// final String dbPassword = (String) envCtx
		// .lookup(ConfigParams.DB_PASSWORD);
		//
		// System.out.println("Db name is " + dbName);
		// System.out.println("Db Host type is " + dbHost);
		// System.out.println("Db Port type is " + dbPort);
		//
		// lookedUpNames.put(ConfigParams.DB_HOST, dbHost);
		// lookedUpNames.put(ConfigParams.DB_NAME, dbName);
		// lookedUpNames.put(ConfigParams.DB_PORT, dbPort);
		// lookedUpNames.put(ConfigParams.DB_USERNAME, dbUsername);
		// lookedUpNames.put(ConfigParams.DB_PASSWORD, dbPassword);
		//
		// } catch (final NamingException e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// }

	}

	@Override
	public void contextDestroyed(final ServletContextEvent arg0) {
		// lookedUpNames = null;
	}

	/*
	 * TODO :Temporary hack to pass JDNI looked up names to app will have to
	 * find a more elegant solution
	 */
	// public static String getProperty(final String key)
	// //throws LookedUpPropertyNotFoundException {
	// // if (lookedUpNames.containsKey(key)) {
	// // return lookedUpNames.get(key);
	// // } else {
	// // throw new LookedUpPropertyNotFoundException("Could not find " + key);
	// // }
	// }

}
